const mongoUtil = require("./mongo_util")
const collectionName = "student_score"
// 获取热门电视剧
function getData(value, callback) {
    const mmp = mongoUtil.getCollection(collectionName)
    mmp.then(collection => {

        collection.find({
            "SecondaryCollege": value.SecondaryCollege
        }).limit(Number(value.pagesize)).skip((Number(value.page) - 1) * Number(value.pagesize)).toArray(function (err, result) { // 返回集合中所有数据
            if (result.length) {
                console.log(result);
                const classItem = result[0].Secondarystudent.filter((item) => {
                    return item.className === value.className
                })
                if (classItem.length > 0) {
                    const RankingArr = []
                    classItem[0].studentList.forEach((ite) => {
                        ite.schoolYearList.forEach((it) => {
                            if (it.grade === value.grade) {
                                it.score_item.forEach((i) => {
                                    if (i.semester === value.semester) {
                                        RankingArr.push({

                                            student_Number: ite.student_Number,
                                            studentName: ite.studentName,
                                            schoolYear: it.schoolYear,
                                            grade: it.grade,
                                            ...i
                                        })
                                    }

                                })
                            }

                        })
                    })
                    callback(null, {
                        rankingList: [...RankingArr],
                        tatol: classItem[0].studentList.length
                    })
                }


            } else {
                // console.log("hhhhhhhh");
                callback(err ? err : {
                    reason: "没有数据"
                }, result)
            }
        });


    })
}

module.exports = {
    getData
}